package com.yehuishou.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.yehuishou.dao.BidItemDao;
import com.yehuishou.dao.FileDao;
import com.yehuishou.pojo.BidItem;
import com.yehuishou.service.BidItemService;


@Service
public class BidItemServiceImpl implements BidItemService {

	@Resource
	private BidItemDao bidItemDao;
	
	@Resource
	private FileDao fileDao;
	
	@Override
	public List<BidItem> getAll() {
		List<BidItem> bids = bidItemDao.getAll();
		for(int i=0;i<bids.size();i++) {
	     String url =bids.get(i).getImg_url();
	   if(url!=null) {
	   String[] img_url=url.split(";");
	    if(img_url.length>1) {
	    	bids.get(i).setImg_url(fileDao.getOneImage(Integer.parseInt(img_url[1])).getFilePath());
	    	}
		}
		
		}
		
		return bids;
	}

	@Override
	public BidItem getOne(Integer bid) {
		BidItem bidItem  =bidItemDao.getOne(bid);
		 String url =bidItem.getImg_url();
		  if(url!=null) {
			 String []img_url=url.split(";");
			 if(img_url.length>1) {
		bidItem.setImg_url(fileDao.getOneImage(Integer.parseInt(img_url[1])).getFilePath());
			 }
		}
		return bidItem;
	}

	@Override
	public void changBidStatus(BidItem bi) {
		bidItemDao.changBidStatus(bi);
		
	}

}
